/*
 * Project Name: showtao
 * File Name: CommonValidator.java
 * Class Name: CommonValidator
 *
 * Copyright 2014 showtao.com
 *
 * Licensed under the showtao.com
 *
 * http://showtao.com
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.showtao.front.validation;

import org.springframework.context.support.ApplicationObjectSupport;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

/**
 * Class Name: CommonValidator Description: do some common validation in here.
 * 
 * @author minhuang
 * 
 */
public abstract class CommonValidator extends ApplicationObjectSupport implements Validator {

    /**
     * 
     * Description: the method need to be implemented for enhance the support taking target.
     * 
     * @param clazz
     * @return
     */
    public abstract boolean supports(final Class<?> clazz);

    /**
     * 
     * Description: get service name.
     * 
     * @param beanName
     * @return
     */
    public Object getBean(String beanName) {
        return getApplicationContext().getBean(beanName);
    }

    /**
     * Description: do the common validate.
     * 
     * @param target
     * @param errors
     */
    protected void commonValidate(final Object target, final Errors errors) {
        // do common validation here.
    }
}
